package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.RoomType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * @author Pang
 */
@Repository
public interface IRoomTypeMapper {

    /**
     * 添加类型
     * @param type
     * @return
     */
    @Insert("INSERT INTO g_roomtype VALUES(#{typeId},#{typeName},#{typePrice},#{typeBedNum}," +
            "#{typePeonum},#{typeComm})")
    int insert(RoomType type);


    /**
     * 删除类型
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_roomtype WHERE type_id=#{id}")
    int delete(Integer id);


    /**
     * 修改类型
     * @param type
     * @return
     */
    @Update("UPDATE g_roomtype SET type_name=#{typeName},type_price=#{typePrice},type_bednum=#{typeBedNum},\" +\n" +
            "            \"type_peonum=#{typePeonum},type_comm=#{typeComm} WHERE type_id=#{typeId}")
    int update(RoomType type);


    /**
     * 根据id查找
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_roomtype WHERE type_id = #{id}")
    RoomType selectById(int id);


    /**
     * 全部查找
     * @return
     */
    @Select("SELECT * FROM g_roomtype")
    @Results(value = {
            @Result(id = true,column = "type_id", property = "typeId"),
            @Result(column = "type_id", property = "roomInfos",many = @Many(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectByTypeId",fetchType = FetchType.LAZY))
    })
    List<RoomType> selectAll();

    /**
     * 查询所有
     * @return
     */
    @Select("SELECT * FROM g_roomtype")
    List<RoomType> selectByTypeAll();
}
